// 注册
export const SIGINUP = 'SIGINUP';
export const SIGINUP_SUCCESS = 'SIGINUP_SUCCESS';
export const SIGINUP_FAIL = 'SIGINUP_FAIL';
export const RESET_SIGNUP = 'RESET_SIGNUP';

export interface SignupPayload {
  email: string;
  name: string;
  password: string;
}

export interface SignupAction {
  type: typeof SIGINUP;
  payload: SignupPayload;
}

export interface SignupSuccessAction {
  type: typeof SIGINUP_SUCCESS;
}

export interface SignupFailAction {
  type: typeof SIGINUP_FAIL;
  message: string;
}
export interface ResetSignupAction {
  type: typeof RESET_SIGNUP;
}

// 定义actioncreator
export const signup = (payload: SignupPayload): SignupAction => ({
  type: SIGINUP,
  payload
});

export const signupSuccess = (): SignupSuccessAction => ({ type: SIGINUP_SUCCESS });

export const signupFail = (message: string): SignupFailAction => ({ type: SIGINUP_FAIL, message });

export const resetSignup = (): ResetSignupAction => ({ type: RESET_SIGNUP });

// 登录
export const SIGNIN = 'SIGNIN';
export const SIGNIN_SUCCESS = 'SIGNIN_SUCCESS';
export const SIGNIN_FAIL = 'SIGNIN_FAIL';

export interface SigninPayload {
  email: string;
  password: string;
}

export interface SigninAction {
  type: typeof SIGNIN;
  payload: SigninPayload;
}

export interface SigninSuccessAction {
  type: typeof SIGNIN_SUCCESS;
}

export interface SigninFailAction {
  type: typeof SIGNIN_FAIL;
  message: string;
}

export const signin = (payload: SigninPayload): SigninAction => ({ type: SIGNIN, payload });

export const signinSuccess = (): SigninSuccessAction => ({ type: SIGNIN_SUCCESS });

export const signinFail = (message: string): SigninFailAction => ({ type: SIGNIN_FAIL, message });

// 导出一个联合类型
export type AuthUnionType = SignupAction | SignupSuccessAction | SignupFailAction | ResetSignupAction | SigninAction | SigninSuccessAction | SigninFailAction;
